﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Server
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        private void _ReceiveMessage()
        {
            txtMessage.Dispatcher.Invoke(new Action(() => { txtMessage.Text += ServerCore.Receive() + "\n"; })); 
        }

        public MainWindow()
        {
            InitializeComponent();
        }

        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            btnStart.IsEnabled = false;
            ServerCore.ReceivingMessageEvent += _ReceiveMessage;
            ServerCore.Start();
            btnStop.IsEnabled = true;
        }

        private void btnStop_Click(object sender, RoutedEventArgs e)
        {
            btnStop.IsEnabled = false;
            ServerCore.ReceivingMessageEvent -= _ReceiveMessage;
            ServerCore.Stop();
            btnStart.IsEnabled = true;
        }
    }
}
